<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>万息金融-后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8"/>
    <link rel="stylesheet" href="/admin/css/font.css">
    <link rel="stylesheet" href="/admin/css/xadmin.css">
    <script src="/admin/js/jquery.min.js"></script>
    <script src="/admin/lib/layui/layui.js" charset="utf-8"></script>
    <script src="/admin/js/myAjax.js"></script>
    <script src="/admin/js/common.js"></script>
    <script type="text/javascript" src="/admin/js/xadmin.js"></script>
    <script src="/admin/js/intercept.js"></script>
</head>

<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">

        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="name" placeholder="姓名" autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="phone" placeholder="电话" autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="email" placeholder="邮箱" autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text"  placeholder="创建时间起始" autocomplete="off" name="startTime" id="start"
                                   class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" placeholder="创建时间截止" autocomplete="off" name="endTime" id="end"
                                   class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sreach">
                                <i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table" id="test" lay-data="{toolbar: '#insert',id:'test'}" lay-filter="bcfilt">
                        <!--    <thead>
                            <tr>
                                <th lay-data="{type:'checkbox'}">ID</th>
                                <th lay-data="{field:'username', width:120, sort: true, edit: 'text'}">头衔</th>
                                <th lay-data="{field:'email', edit: 'text', minWidth: 150}">照片</th>
                                <th lay-data="{field:'sex', minWidth:80}">个人介绍</th>
                                <th lay-data="{field:'city', edit: 'text', minWidth: 100}">创建时间</th>
                                <th lay-data="{field:'experience', sort: true, edit: 'text'}">修改时间</th>
                                <th lay-data="{field:'dw_xinzhi',templet: function(d){ return d.dw_xinzhi.titel;}}">批注</th>
                            </tr>
                            </thead>-->
                    </table>
                </div>
            </div>
        </div>
    </div>

</div>
</div>
</body>

<script type="text/html" id="operation">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="delete">删除</a>
</script>
<script>
    layui.use(['table', 'jquery','form','laydate'], function () {
        var $ = layui.jquery,
            table = layui.table
            , form = layui.form
            ,laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素

        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
        //留言
        table.render({
            elem: '#test'
            , page: true
            , url: ipAddress()+"/user/message/g"
            , method: 'get'
            , text: '没有数据'
            ,headers:{
                'Authorization':localStorage.getItem("Authorization")
            }
            , cols: [[
                {field: 'name', minWidth: 100, title: '姓名'}
                , {field: 'phone', minWidth: 100, title: '电话'}
                , {field: 'email', minWidth: 100, title: '邮箱'}
                , {field: 'content', minWidth: 100,event:'showContent', title: '留言'}
                , {field: 'createTime', minWidth: 100, title: '创建时间'}
                , {field: 'updateTime', sort: true, title: '批注时间'}
                , {field: 'remark',edit:true, title: '批注'}
                , {fixed: 'right', width: 160, align: 'center', toolbar: '#operation', title: '操作'}
            ]]
        });

        //监听单元格编辑
        table.on('edit(bcfilt)',
            function(obj) {
                let data={'id':obj.data.id,'remark':obj.value}
                let res=myAjax(ipAddress()+"/user/message/u",data,"put")
                if(res.count==1){
                     layer.msg("同步成功");
                 }else{
                    layer.msg("同步失败");
                }

            });

        //单元格工具事件：编辑  删除
        table.on('tool(bcfilt)', function (obj) {
            var data = obj.data; //获得当前行数据 layui-laypage-count
            switch (obj.event) {
                case 'showContent':
                    layer.open({
                        type: 1,
                        title: false,
                        closeBtn: 0,
                        area: ['516px','400px'],
                        // skin: 'layui-layer-nobg', //没有背景色
                        shadeClose: true,
                        content: '<div>'+data.content+' </div>'
                    });
                    break;
                case 'delete':
                    layer.confirm('确认要删除吗？', function (index) {
                        let indx = table.cache.test.length;
                        //发异步删除数据
                        let res = myAjax(ipAddress()+'/user/message/d/'+data.id, {}, "delete");
                        let pg=$(".layui-laypage-curr").children().eq(1).text();
                        if (res.count == 1) {
                            if (indx == 1) {
                                table.reload('test', {page: {curr: pg-1}})
                            } else {
                                table.reload('test', {})
                            }
                            layer.msg('已删除!', {icon: 1, time: 1000});
                        } else {
                            layer.msg('删除失败!', {icon: 1, time: 1000});
                        }
                    });

                    break;
            };});


        form.on('submit(sreach)',
            function (data) {
                //执行渲染
                table.render({
                    elem: '#test'
                    , page: true
                    ,method:'get'
                    ,headers:{
                        'token':localStorage.getItem('token')
                    }
                    , url: ipAddress()+"/user/message/g"
                    , text: '没有数据'
                    , where: data.field
                    , cols:[[
                        {field: 'name', minWidth: 100, title: '姓名'}
                        , {field: 'phone', minWidth: 100, title: '电话'}
                        , {field: 'email', minWidth: 100, title: '邮箱'}
                        , {field: 'content', minWidth: 100,event:'showContent', title: '留言'}
                        , {field: 'createTime', minWidth: 100, title: '创建时间'}
                        , {field: 'updateTime', sort: true, title: '批注时间'}
                        , {field: 'remark',edit:true, title: '批注'}
                        , {fixed: 'right', width: 160, align: 'center', toolbar: '#operation', title: '操作'}
                    ]]
                });
                return false;
            })


    })
</script>
</html>